
# REQUIRES: Data/Roper Data.csv

# NOTE: Uses code from Stargazer Package Updates.R instead of the published version of Stargazer. See readme.txt.

################# Dependencies #################
# source("Load Packages.R")
# source("Analysis - Roper/Cleaning.R")

################# Table S3 - Predictors of US Public Support for Withdrawal, 1946-2021 #################
# With question features and percent of options that were for withdrawal
OLS_q <- lm(percwithdraw ~  bEnemyVictory + bDeescalationOption + bOnesidedquestion + responseoptions,
            data = roper)

# With situation features
OLS_s <- lm(percwithdraw ~  logcas + FPR + Vietnam + Gulf_War + Afghanistan + Iraq, 
            data = roper)

# With question and situation features
OLS_qs <- lm(percwithdraw ~  bEnemyVictory + bDeescalationOption + bOnesidedquestion + responseoptions 
             + logcas + FPR + Vietnam + Gulf_War + Afghanistan + Iraq, 
             data = roper)

# Table 1 with clustered standard errors by campaign
cOLS_q <- coeftest(OLS_q, vcov = vcovCL, df = 5, cluster = ~numcampaign2)
cOLS_s <- coeftest(OLS_s, vcov = vcovCL, df = 5, cluster = ~numcampaign2)
cOLS_qs <- coeftest(OLS_qs, vcov = vcovCL, df = 5, cluster = ~numcampaign2)

output <- stargazer(cOLS_q, cOLS_s, cOLS_qs, title="Table A3: Replication of Observational Results with SEs Clustered by Campaign",
                    align=TRUE, dep.var.labels=c(""), dep.var.caption="",
                    column.labels=c(" ","",""),
                    digits = 3, digits.extra = 0,
                    notes = "P-value shown in parentheses below coefficient", 
                    notes.append = FALSE,
                    report = "vc*p",
                    covariate.labels=c("Enemy Victory Framing", "Troop Reduction Option", "One-sided Question",
                                       "No. of Response Options", "Log Cumulative Casualties", "Foreign Policy Restraint",
                                       "Vietnam", "Gulf War", "Afghanistan", "Iraq", "Constant"),
                    omit.stat=c("LL","ser","f","adj.rsq"), no.space=TRUE, notes.align="c", out = "Plots/Table S3 - Predictors of US Public Support for Withdrawal, 1946-2021_R.html")

webshot("Plots/Table S3 - Predictors of US Public Support for Withdrawal, 1946-2021_R.html", "Plots/Table S3 - Predictors of US Public Support for Withdrawal, 1946-2021_R.png", zoom=5, vwidth=580, vheight=600)
# Note: Add the independent variable groups in Word and remove "_R" from the file name
# webshot("Plots/Table S3 - Predictors of US Public Support for Withdrawal, 1946-2021.html", "Plots/Table S3 - Predictors of US Public Support for Withdrawal, 1946-2021.png", zoom=5, vwidth=500, vheight=580)

rm(OLS_q, OLS_qs, OLS_s, cOLS_q, cOLS_qs, cOLS_s, output)
